package com.tn.service.rpm.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.tn.controller.alarm.common.model.rpm.CameraAreaListResultVO;
import com.tn.controller.alarm.common.model.rpm.RpmRequestVO;
import com.tn.controller.alarm.common.model.rpm.RpmResponseVO;
import com.tn.utils.HttpRequestSenderUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClassName RmpHttpRequest
 * @Description TODO
 * @Author Yezhongzhu
 * @Date 2021/12/27 9:24
 * @Version v1.0
 **/
@Component
public class RpmHttpRequest {
    @Value("${position-system.rmp-url}")
    private String baseUrl;
    @Value("${position-system.rmp-sync}")
    private String syncMethod;
    @Value("${position-system.rmp-async}")
    private String asyncMethod;

    public RpmResponseVO<Map<String,String[]>> rmpSync(RpmRequestVO rmpRequestVO){
        String pathUrl = new StringBuilder(baseUrl).append(syncMethod).toString();
        String body = HttpRequestSenderUtil.postString(pathUrl,null, JSON.toJSONString(rmpRequestVO));
        RpmResponseVO<Map<String,String[]>> rmpResponseVO = JSON.parseObject(body,new TypeReference<RpmResponseVO<Map<String,String[]>>>(){});
        return rmpResponseVO;
    }

    public RpmResponseVO<List<CameraAreaListResultVO>> rmpSyncList(RpmRequestVO rmpRequestVO){
        String pathUrl = new StringBuilder(baseUrl).append(syncMethod).toString();
        String body = HttpRequestSenderUtil.postString(pathUrl,null, JSON.toJSONString(rmpRequestVO));
        RpmResponseVO<List<CameraAreaListResultVO>> rmpResponseVO = JSON.parseObject(body,new TypeReference<RpmResponseVO<List<CameraAreaListResultVO>>>(){});
        return rmpResponseVO;
    }

    public RpmResponseVO rmpAsync(RpmRequestVO rmpRequestVO){
        String pathUrl = new StringBuilder(baseUrl).append(asyncMethod).toString();
        String body = HttpRequestSenderUtil.postString(pathUrl,null, JSON.toJSONString(rmpRequestVO));
        RpmResponseVO rmpResponseVO = JSON.parseObject(body,new TypeReference<RpmResponseVO>(){});
        return rmpResponseVO;
    }
}